import { RECORD_USERINFO, GET_USERINFO, OUT_LOGIN } from './mutation-types'
import { setStore } from '../config/mUtils'
export default {
  [RECORD_USERINFO] (state, info) {
    state.userInfo = info
    state.login = true
    setStore('user_id', info.user_id)
  },
  [GET_USERINFO] (state, info) {
    if (state.userInfo && (state.userInfo.username !== info.username)) {
      console.log(state)
      return
    };
    if (!state.login) {
      return
    }
    if (!info.message) {
      state.userInfo = { ...info }
    } else {
      state.userInfo = null
    }
  },
  // 退出登录
  [OUT_LOGIN] (state) {
    state.userInfo = null
  }
}
